import { Controller } from "../../mvc/core/Controller";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { EPlayerItemPosType } from "../../../Message/Public/EPlayerItemPosType";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { Alert } from "../../../com/mui/controls/Alert";
import { Language } from "../../../extend/language/Language";
import { ItemData } from "../resource/info/ItemData";
import { SystemSetter } from "../view/system/SystemSetter";
import { DelegateConfig } from "../resource/DelegateConfig";
import { DelegateTaskData } from "../view/delegate/cell/DelegateTaskData";
import { IView } from "../../mvc/interfaces/IView";
import { DelegateTaskModule } from "../../../modules/DelegateTaskModule";
import { WindowEvent } from "../../component/window/WindowEvent";
import { GModuleEvent } from "../mvc/GModuleEvent";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../scene/events/PlayerEvent";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SMyDelegate } from "../../../Message/Game/SMyDelegate";
import { SCanDelegate } from "../../../Message/Game/SCanDelegate";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { DataProvider } from "../../../fl/data/DataProvider";
import { DelegateTaskStatus } from "../view/delegate/DelegateTaskStatus";
import { CanDelegateItemData } from "../view/delegate/cell/CanDelegateItemData";
import { EPrictUnit } from "../../../Message/Public/EPrictUnit";
import { CopyUtil } from "../view/copy/CopyUtil";
import { CopyConfig } from "../resource/CopyConfig";
import { TDelegate } from "../../../Message/Db/Tables/TDelegate";
import { EDelegateType } from "../../../Message/Game/EDelegateType";
import { PulseSharedObject } from "../view/player/PulseSharedObject";
import { TodayNoTipsConst } from "../../component/gconst/TodayNoTipsConst";
import { SPlayerDelegate } from "../../../Message/Game/SPlayerDelegate";
import { EDelegateKind } from "../../../Message/Game/EDelegateKind";
import { CheckBoxWin } from "../view/common/alertwins/CheckBoxWin";
import { DelegateTaskHintIcon } from "../view/delegateTask/DelegateTaskHintIcon";
import { MsgManager } from "../manager/MsgManager";
import { ECopyType } from "../../../Message/Public/ECopyType";
import { IDelegateTaskModule } from "../../../modules/interfaces/IDelegateTaskModule";
import { DelegateWarehouse } from "../view/delegate/warehouse/DelegateWarehouse";
import { DelegateSettingRule } from "../view/delegate/warehouse/DelegateSettingRule";
import { _EPlayerItemPosTypeDelegate } from "../../../EPlayerItemPosType/_EPlayerItemPosTypeDelegate";
type int = number;
//class DelegateTaskController
    
    export  class DelegateTaskController extends Controller
    {
       

        /* internal  */onFeedAllDelegateItem(arg1: DataEvent): void
        {
            var loc1=cache.pack.mountsPackCache.equipEdMount;
            if (loc1) 
            {
                GameProxy.mountsProxy.feedMount(EPlayerItemPosType._EPlayerItemPosTypeRole, loc1.uid, EPlayerItemPosType._EPlayerItemPosTypeDelegate, arg1.data as Map<any, any> /* flash.utils.Dictionary */);
            }
            return;
        }

        /* internal  */onFeedSuitSkill(arg1: DataEvent): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.SuitSkillAddQi, {"posType": _EPlayerItemPosTypeDelegate, "items": arg1.data}));
            return;
        }

        /* internal  */onDelegateWarehouseItemsUpdate(arg1): void
        {
            if (cache.pack.delegate.itemLength > 0) 
            {
                this.showDelegateHintIcon();
            }
            else 
            {
                this.hideDelegateHintIcon();
            }
            this.updateDelegateItems();
            this.checkWarehouseEffect();
            if (this._delegateWarehouse && !this._delegateWarehouse.isHide && !this.hasWarehouseItem()) 
            {
                this._delegateWarehouse.hide();
            }
            return;
        }

        /* internal  */onGetDelegateCopyCopyCoin(arg1: int): void
        {
            Alert.show(Language.getStringByParam(69667, arg1));
            return;
        }

        /* internal  */updateDelegateItems(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            if (this._delegateWarehouse && !this._delegateWarehouse.isHide) 
            {
                loc1 = cache.pack.delegate.getAllItems();
                loc2 = [];
                var loc4=0;
                var loc5=loc1;
                for(loc3 of loc5) 
                {
                    if (!loc3) 
                    {
                        continue;
                    }
                    loc2.push(loc3);
                }
                this._delegateWarehouse.updateItems(loc2);
            }
            return;
        }

        /* internal  */checkWarehouseEffect(): void
        {
            var loc1=false;
            if (this._delegateTaskModule && !this._delegateTaskModule.isHide) 
            {
                loc1 = this.hasWarehouseItem();
                if (loc1) 
                {
                    this._delegateTaskModule.addWarehouseBtnEffect();
                }
                else 
                {
                    this._delegateTaskModule.removeWarehouseBtnEffect();
                }
            }
            return;
        }

        public getLists(): void
        {
            GameProxy.delegateTask.myDelegate();
            GameProxy.delegateTask.canDelegate();
            return;
        }

        /* internal  */hasWarehouseItem(): Boolean
        {
            var loc3=null;
            var loc1=false;
            var loc2=cache.pack.delegate.getAllItems();
            var loc4=0;
            while (loc4 < loc2.length) 
            {
                if (loc2[loc4] && loc2[loc4] is ItemData) 
                {
                    loc1 = true;
                    break;
                }
                ++loc4;
            }
            return loc1;
        }

        /* internal  */onDelegateSettingInfoChange(arg1: DataEvent): void
        {
            var loc3=null;
            var loc1=arg1.data as Map<any, any> /* flash.utils.Dictionary */;
            var loc2=SystemSetter.localSetter.delegateSetting;
            loc2.splice(0);
            var loc4=0;
            var loc5=loc1;
            for (loc3 in loc5) 
            {
                if (loc1[loc3] != true) 
                {
                    continue;
                }
                loc2.push(parseInt(loc3));
            }
            return;
        }

        /* internal  */onShowDelegateTaskWindow(arg1: DataEvent): void
        {
            var loc1=0;
            this.getLists();
            view.show();
            if (arg1.data) 
            {
                loc1 = arg1.data as int;
            }
            else 
            {
                loc1 = DelegateConfig.instance.getFirstCopyCode();
            }
            var loc2=this.getDelegateDataByCode(loc1);
            if (loc2) 
            {
                this.updateDelegateTasks(loc2, true);
            }
            return;
        }

        /* internal  */getDelegateDataByCode(arg1: int): DelegateTaskData
        {
            var loc1=null;
            var loc2=0;
            if (!this._inited) 
            {
                this.initDelegateData();
            }
            loc2 = 0;
            while (loc2 < this._delegateTaskList.length) 
            {
                loc1 = this._delegateTaskList.getItemAt(loc2) as DelegateTaskData;
                if (loc1.tdelegate.code == arg1) 
                {
                    return loc1;
                }
                ++loc2;
            }
            loc2 = 0;
            while (loc2 < this._delegateTaskList_defenceCopy.length) 
            {
                loc1 = this._delegateTaskList_defenceCopy.getItemAt(loc2) as DelegateTaskData;
                if (loc1.tdelegate.code == arg1) 
                {
                    return loc1;
                }
                ++loc2;
            }
            loc2 = 0;
            while (loc2 < this._delegateTaskList_CrossDefence.length) 
            {
                loc1 = this._delegateTaskList_CrossDefence.getItemAt(loc2) as DelegateTaskData;
                if (loc1.tdelegate.code == arg1) 
                {
                    return loc1;
                }
                ++loc2;
            }
            return null;
        }

        /* internal  */onModuleShow(arg1: Object /* flash.events.Event */): void
        {
            this.checkWarehouseEffect();
            if (!this._reqTimer) 
            {
                this._reqTimer = new Object /* flash.utils.Timer */(15000);
                this._reqTimer.addEventListener(flash.events.TimerEvent.TIMER, this.onReqTimerEvent);
            }
            if (!this._reqTimer.running) 
            {
                this._reqTimer.start();
            }
            return;
        }

        /* internal  */onModuleClose(arg1: Object /* flash.events.Event */): void
        {
            if (this._reqTimer && this._reqTimer.running) 
            {
                this._reqTimer.stop();
            }
            return;
        }

        protected /* override */ initView(): IView
        {
            if (!this._delegateTaskModule) 
            {
                this._delegateTaskModule = new DelegateTaskModule();
                this._delegateTaskModule.addEventListener(WindowEvent.SHOW, this.onModuleShow);
                this._delegateTaskModule.addEventListener(WindowEvent.CLOSE, this.onModuleClose);
                this._delegateTaskModule.addEventListener(GModuleEvent.StartDelegateTaskCoin, this.onDelegateTaskCoin);
                this._delegateTaskModule.addEventListener(GModuleEvent.StartDelegateTaskGold, this.onDelegateTaskGold);
                this._delegateTaskModule.addEventListener(GModuleEvent.StartDelegateTaskFree, this.onDelegateTaskFree);
                this._delegateTaskModule.addEventListener(GModuleEvent.OpenDelegateWarehouse, this.onOpenDelegateWarehouse);
                this._delegateTaskModule.addEventListener(GModuleEvent.ShowNextDelegateTask, this.onShowNextDelegateTask);
                NetDispatcher.addCmdListener(ServerCommand.BufferUpdate, this.onRoleStatusUpdate);
                NetDispatcher.addCmdListener(ServerCommand.VIPInfoUpdateCommand, this.onRoleStatusUpdate);
                RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onRoleStatusUpdate);
                NetDispatcher.addCmdListener(ServerCommand.RoleFightCombatCapabilities, this.onRoleStatusUpdate);
            }
            return this._delegateTaskModule;
        }

        /* internal  */onReqTimerEvent(arg1: Object /* flash.events.Event */): void
        {
            this.getLists();
            return;
        }

        /* internal  */onReceiveMyDelegate(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SMyDelegate;
            cache.delegateTask.myDelegate = loc1;
            return;
        }

        /* internal  */onReceiveCanDelegate(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SCanDelegate;
            cache.delegateTask.canDelegate = loc1;
            this.updateDelegateTasks(null);
            return;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.ShowDelegateTaskWindow, this.onShowDelegateTaskWindow);
            Dispatcher.addEventListener(EventName.ShowDelegateWareHouse, this.onOpenDelegateWarehouse);
            Dispatcher.addEventListener(EventName.DelegateWarehouse_GetAll, this.onGetAllDelegateItem);
            Dispatcher.addEventListener(EventName.DelegateWarehouse_GetAllSuccess, this.onGetAllItemsSuccess);
            Dispatcher.addEventListener(EventName.DelegateSettingInfo, this.onDelegateSettingInfoChange);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateMyDelegate, this.onReceiveMyDelegate);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateCanDelegate, this.onReceiveCanDelegate);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateCompleteDelegate, this.onDelegateComplete);
            NetDispatcher.addCmdListener(ServerCommand.DelegateWarehouseItemsUpdate, this.onDelegateWarehouseItemsUpdate);
            NetDispatcher.addCmdListener(ServerCommand.DelegateCoinCopyReward, this.onGetDelegateCopyCopyCoin);
            return;
        }

        /* internal  */initDelegateData(): void
        {
            var loc2=null;
            var loc3=null;
            this._inited = true;
            this._delegateTaskList = new DataProvider();
            this._delegateTaskList_defenceCopy = new DataProvider();
            this._delegateTaskList_AllWithHighestDefence = new DataProvider();
            this._delegateTaskList_CrossDefence = new DataProvider();
            var loc1=DelegateConfig.instance.copyMap;
            var loc4=0;
            var loc5=loc1;
            for(loc3 of loc5) 
            {
                loc2 = new DelegateTaskData(loc3);
                if (loc2.isDefenceCopy()) 
                {
                    this._delegateTaskList_defenceCopy.addItem(loc2);
                    if (loc2.isHighestDefenceCopy()) 
                    {
                        this._delegateTaskList_AllWithHighestDefence.addItem(loc2);
                    }
                    continue;
                }
                if (loc2.isCrossDefenceCopy()) 
                {
                    this._delegateTaskList_CrossDefence.addItem(loc2);
                    continue;
                }
                this._delegateTaskList.addItem(loc2);
                this._delegateTaskList_AllWithHighestDefence.addItem(loc2);
            }
            return;
        }

        /* internal  */updateDelegateTasks(arg1: DelegateTaskData, arg2: Boolean=false): void
        {
            var loc2=null;
            var loc4=null;
            if (!this._inited) 
            {
                this.initDelegateData();
            }
            var loc1=this.getDataProvider(arg1);
            var loc3=0;
            while (loc3 < loc1.length) 
            {
                loc2 = loc1.getItemAt(loc3) as DelegateTaskData;
                if (this.isDelegateComplete(loc2.tdelegate)) 
                {
                    loc2.status = DelegateTaskStatus.Complete;
                }
                else if (this.isDelegating(loc2.tdelegate)) 
                {
                    loc2.status = DelegateTaskStatus.Delegating;
                }
                else if (cache.delegateTask.isCanDelegate(loc2.tdelegate)) 
                {
                    loc2.status = DelegateTaskStatus.CanDelegate;
                }
                else 
                {
                    loc2.status = DelegateTaskStatus.UnReach;
                }
                ++loc3;
            }
            loc1.sortOn(["status", "code"], [Array.NUMERIC, Array.NUMERIC]);
            if (this._delegateTaskModule && !this._delegateTaskModule.isHide) 
            {
                this._delegateTaskModule.updateDelegateTask(loc1);
                if (loc1 != this._delegateTaskList_defenceCopy) 
                {
                    this._delegateTaskModule.updateTip(Language.getString(69665));
                }
                else 
                {
                    this._delegateTaskModule.updateTip(Language.getString(69710));
                }
                if (arg1 && !(this._delegateTaskModule.selectedDelegate.code == arg1.code)) 
                {
                    this._delegateTaskModule.setSelectedDelegateData(arg1);
                }
                else if (this.showToNext()) 
                {
                    this._tempDelegateTaskCode = 0;
                    this.onShowNextDelegateTask();
                }
                if (arg2 && arg1 && arg1.isCrossDefenceCopy()) 
                {
                    loc4 = loc1.getItemAt(1) as DelegateTaskData;
                    if (!this._info) 
                    {
                        this._info = new CanDelegateItemData();
                        this._info.moneyType = EPrictUnit._EPriceUnitGold;
                    }
                    this._info.data = loc4;
                    if (this._info.isReachLevel() && this._info.data.tdelegate.passTimes <= cache.copy.getDelegateCopyPassTimes(this._info.data.code) && !this._info.copyNumOver && !this._info.isDelegating) 
                    {
                        this._delegateTaskModule.setSelectedDelegateData(loc4);
                    }
                    else 
                    {
                        this._delegateTaskModule.setSelectedDelegateData(loc1.getItemAt(0) as DelegateTaskData);
                    }
                }
            }
            return;
        }

        /* internal  */getDataProvider(arg1: DelegateTaskData): DataProvider
        {
            if (this._delegateTaskModule && this._delegateTaskModule.taskList && (!arg1 || !(this._delegateTaskModule.taskList.getItemIndex(arg1) == -1))) 
            {
                return this._delegateTaskModule.taskList;
            }
            if (arg1 && arg1.isCrossDefenceCopy()) 
            {
                return this._delegateTaskList_CrossDefence;
            }
            if (arg1 && arg1.isDefenceCopy() && !arg1.isHighestDefenceCopy()) 
            {
                return this._delegateTaskList_defenceCopy;
            }
            if (this.reachHighestDefenceCondition()) 
            {
                return this._delegateTaskList_AllWithHighestDefence;
            }
            if (arg1 && arg1.isDefenceCopy()) 
            {
                return this._delegateTaskList_defenceCopy;
            }
            return this._delegateTaskList;
        }

        /* internal  */reachHighestDefenceCondition(): Boolean
        {
            var loc1=null;
            var loc2=null;
            var loc3=DelegateConfig.instance.copyMap;
            var loc4=0;
            var loc5=loc3;
            for(loc2 of loc5) 
            {
                if (!CopyUtil.isHighestDefenceCopy(CopyConfig.instance.getInfoByCode(loc2.code))) 
                {
                    continue;
                }
                loc1 = loc2;
                break;
            }
            if (loc1) 
            {
                return cache.copy.getDelegateCopyPassTimes(loc1.code) >= loc1.passTimes;
            }
            return false;
        }

        /* internal  */isDelegateComplete(arg1: TDelegate): Boolean
        {
            var loc1=0;
            var loc2=0;
            if (arg1.type == EDelegateType._EDelegateTypeCopy) 
            {
                loc1 = cache.copy.getHasEnterNumById(arg1.code);
                loc2 = cache.copy.getTotalEnterNumById(arg1.code);
                if (loc1 >= loc2 && !this.isDelegating(arg1)) 
                {
                    return true;
                }
            }
            return false;
        }

        /* internal  */isDelegating(arg1: TDelegate): Boolean
        {
            if (cache.delegateTask.getMyDelegate(arg1.code) != null) 
            {
                return true;
            }
            return false;
        }

        /* internal  */onDelegateComplete(arg1: MessageBlock): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc7=null;
            var loc1=arg1.messageBase as SMyDelegate;
            if (!PulseSharedObject.isTodayNotTips(TodayNoTipsConst.CompleteDelegateTaskTip) && loc1.playerDelegates.length > 0) 
            {
                loc2 = DelegateConfig.instance;
                loc3 = loc1.playerDelegates[0] as SPlayerDelegate;
                loc4 = loc2.getDelegateInfoByCode(loc3.delegateCode);
                if (!(loc3.type == EDelegateKind._EDelegateKindFree) && loc4) 
                {
                    if (loc3.type == EDelegateKind._EDelegateKindCoin && !(loc4.timeCoin == 0) || loc3.type == EDelegateKind._EDelegateKindGold && !(loc4.timeGold == 0)) 
                    {
                        loc5 = loc2.getDelegateName(loc4);
                        loc6 = loc2.getDelegateExp(loc3.type, loc4);
                        loc6 = Math.round(loc6 + loc6 * loc3.isActive / 100) * loc3.count;
                        loc7 = Language.getStringByParam(69625, loc5, loc6);
                        Alert.alertWinRenderer = CheckBoxWin;
                        Alert.buttonWidth = 70;
                        Alert.extendObj = loc4;
                        Alert.calcelLabel = Language.getString(69652);
                        Alert.show(loc7, Language.getString(69900), Alert.OK | Alert.CANCEL, null, this.onCompleteDelegateTaskAlert);
                    }
                }
            }
            this.getLists();
            this.checkWarehouseEffect();
            if (this.hasWarehouseItem()) 
            {
                this.showDelegateHintIcon();
            }
            return;
        }

        /* internal  */showDelegateHintIcon(): void
        {
            if (!this._delegateHintIcon) 
            {
                this._delegateHintIcon = new DelegateTaskHintIcon();
            }
            this._delegateHintIcon.show();
            return;
        }

        /* internal  */hideDelegateHintIcon(): void
        {
            if (this._delegateHintIcon) 
            {
                this._delegateHintIcon.hide();
            }
            return;
        }

        /* internal  */onCompleteDelegateTaskAlert(arg1: int, arg2: TDelegate, arg3: Boolean): void
        {
            if (arg1 == Alert.CANCEL) 
            {
                this.onShowDelegateTaskWindow(new DataEvent("", arg2.code));
            }
            if (arg3) 
            {
                PulseSharedObject.save(TodayNoTipsConst.CompleteDelegateTaskTip, true);
            }
            return;
        }

        /* internal  */onDelegateTaskCoin(arg1: DataEvent): void
        {
            var loc1=arg1.data.data as TDelegate;
            var loc2=arg1.data.count as int;
            this.delegateTask(EDelegateKind._EDelegateKindCoin, loc1.code, loc2);
            return;
        }

        /* internal  */onDelegateTaskGold(arg1: DataEvent): void
        {
            var loc1=arg1.data.data as TDelegate;
            var loc2=arg1.data.count as int;
            this.delegateTask(EDelegateKind._EDelegateKindGold, loc1.code, loc2);
            return;
        }

        /* internal  */onDelegateTaskFree(arg1: DataEvent): void
        {
            var loc1=arg1.data.data as TDelegate;
            var loc2=arg1.data.count as int;
            this.delegateTask(EDelegateKind._EDelegateKindFree, loc1.code, loc2);
            return;
        }

        /* internal  */delegateTask(arg1: int, arg2: int, arg3: int): void
        {
            var loc3=0;
            var loc4=0;
            var loc5=0;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc9=0;
            var loc10=0;
            var loc11=null;
            var loc12=null;
            var loc13=null;
            var loc1;
            var loc2;
            if (loc2 = (loc1 = DelegateConfig.instance).getDelegateInfoByCode(arg2)) 
            {
                loc3 = cache.role.money.coinBind + cache.role.money.coin;
                loc4 = cache.role.money.gold;
                if (arg1 == EDelegateKind._EDelegateKindCoin && loc2.coin > loc3) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(69623));
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, loc2.coin - loc3));
                    return;
                }
                if (arg1 == EDelegateKind._EDelegateKindGold && loc2.gold > loc4) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(69624));
                    return;
                }
                if (arg1 == EDelegateKind._EDelegateKindFree && PulseSharedObject.isTodayNotTips(TodayNoTipsConst.DelegateTaskTipFree) || !(arg1 == EDelegateKind._EDelegateKindFree) && PulseSharedObject.isTodayNotTips(TodayNoTipsConst.DelegateTaskTip)) 
                {
                    this.startDelegate(arg2, arg1, arg3);
                }
                else 
                {
                    loc5 = loc1.getCost(arg1, loc2) * arg3;
                    loc6 = loc1.getTypeName(arg1);
                    loc7 = loc1.getDelegateName(loc2);
                    loc8 = loc1.getTime(arg1, loc2) * arg3 + "";
                    loc9 = loc1.getDelegateExp(arg1, loc2);
                    loc10 = cache.delegateTask.getExpAddVIP() + cache.delegateTask.getExpAddDrug();
                    loc9 = Math.round(loc9 + loc9 * loc10 / 100) * arg3;
                    loc11 = loc1.getRewardDesc(loc2);
                    if (arg1 != EDelegateKind._EDelegateKindFree) 
                    {
                        loc12 = Language.getStringByParam(69620, loc5 + loc6, arg3, loc7, loc8, loc9, loc11);
                    }
                    else if ((loc13 = CopyConfig.instance.getInfoByCode(loc2.code)) && loc13.copyType == ECopyType._ECopyCoin) 
                    {
                        loc12 = Language.getStringByParam(69666, loc7);
                    }
                    else 
                    {
                        loc12 = Language.getStringByParam(69663, loc7);
                    }
                    Alert.alertWinRenderer = CheckBoxWin;
                    Alert.extendObj = {"type": arg1, "code": arg2, "count": arg3};
                    Alert.show(loc12, Language.getString(69900), Alert.OK | Alert.CANCEL, null, this.onDelegateTaskAlert);
                }
            }
            return;
        }

        /* internal  */onDelegateTaskAlert(arg1: int, arg2: Object, arg3: int): void
        {
            if (arg1 == Alert.OK) 
            {
                this.startDelegate(arg2.code, arg2.type, arg2.count);
            }
            if (arg3) 
            {
                if (arg2.type != EDelegateKind._EDelegateKindFree) 
                {
                    PulseSharedObject.save(TodayNoTipsConst.DelegateTaskTip, true);
                }
                else 
                {
                    PulseSharedObject.save(TodayNoTipsConst.DelegateTaskTipFree, true);
                }
            }
            return;
        }

        /* internal  */startDelegate(arg1: int, arg2: int, arg3: int): void
        {
            this._tempDelegateTaskCode = arg1;
            GameProxy.delegateTask.startDelegate(arg1, arg2, arg3);
            return;
        }

        /* internal  */showToNext(): Boolean
        {
            if (this._tempDelegateTaskCode == 0 || !this._delegateTaskModule) 
            {
                return false;
            }
            var loc1=this._delegateTaskModule.selectedDelegate;
            if (loc1 && loc1.code == this._tempDelegateTaskCode && !(loc1.status == DelegateTaskStatus.CanDelegate)) 
            {
                return true;
            }
            return false;
        }

        /* internal  */onShowNextDelegateTask(arg1=null): void
        {
            var loc1=arg1 ? true : false;
            var loc2=this.getNextDelegateTask(loc1);
            if (loc2) 
            {
                if (_view && !_view.isHide) 
                {
                    (_view as IDelegateTaskModule).setSelectedDelegateData(loc2);
                }
            }
            return;
        }

        /* internal  */getNextDelegateTask(arg1: Boolean=false): DelegateTaskData
        {
            var loc4=null;
            var loc5=0;
            var loc6=0;
            var loc1=this._delegateTaskModule.selectedDelegate;
            var loc2=this._delegateTaskModule.taskList;
            if (!loc2 || loc2.length == 0) 
            {
                return null;
            }
            var loc3=loc2.getItemIndex(loc1);
            if (!arg1) 
            {
                loc5 = 0;
                while (loc5 < loc2.length) 
                {
                    if ((loc6 = loc3 + loc5 + 1) >= loc2.length) 
                    {
                        loc6 = loc6 - loc2.length;
                    }
                    if ((loc4 = loc2.getItemAt(loc6) as DelegateTaskData) && loc4.status == DelegateTaskStatus.CanDelegate) 
                    {
                        return loc4;
                    }
                    ++loc5;
                }
            }
            if (arg1) 
            {
                if ((loc6 = loc3 + 1) >= loc2.length) 
                {
                    loc6 = loc6 - loc2.length;
                }
                if (loc4 = loc2.getItemAt(loc6) as DelegateTaskData) 
                {
                    return loc4;
                }
            }
            return null;
        }

        /* internal  */onRoleStatusUpdate(arg1): void
        {
            if (this._delegateTaskModule && !this._delegateTaskModule.isHide) 
            {
                this.updateDelegateTasks(this._delegateTaskModule.selectedDelegate);
            }
            return;
        }

        /* internal  */onOpenDelegateWarehouse(arg1: Object /* flash.events.Event */): void
        {
            if (!this._delegateWarehouse) 
            {
                this._delegateWarehouse = new DelegateWarehouse();
                this._delegateWarehouse.addEventListener(WindowEvent.SHOW, this.onDelegateWarehouseShow);
                this._delegateWarehouse.addEventListener(WindowEvent.CLOSE, this.onDelegateWarehouseClose);
                this._delegateWarehouse.addEventListener(GModuleEvent.DelegateWarehouse_Get, this.onGetDelegateItem);
                this._delegateWarehouse.addEventListener(GModuleEvent.DelegateWarehouse_GetAll, this.onGetAllDelegateItem);
                this._delegateWarehouse.addEventListener(GModuleEvent.DelegateWarehouse_destroyAll, this.onDestroyAllDelegateItem);
                this._delegateWarehouse.addEventListener(GModuleEvent.DelegateWarehouse_FeedMount, this.onFeedAllDelegateItem);
                this._delegateWarehouse.addEventListener(GModuleEvent.DelegateWarehouse_FeedSuitSkill, this.onFeedSuitSkill);
            }
            this._delegateWarehouse.show();
            return;
        }

        /* internal  */onDelegateWarehouseShow(arg1: Object /* flash.events.Event */): void
        {
            this.updateDelegateItems();
            return;
        }

        /* internal  */onDelegateWarehouseClose(arg1: Object /* flash.events.Event */): void
        {
            if (this._delegateHintIcon && cache.pack.delegate.itemLength <= 0) 
            {
                this._delegateHintIcon.hide();
            }
            return;
        }

        /* internal  */onGetDelegateItem(arg1: DataEvent): void
        {
            GameProxy.delegateTask.getDelegateBagItems((arg1.data as ItemData).uid);
            return;
        }

        /* internal  */onGetAllDelegateItem(arg1: DataEvent): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=false;
            var loc4=null;
            if (cache.pack.delegate.itemLength <= 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(69651));
                if (this._delegateHintIcon) 
                {
                    this._delegateHintIcon.hide();
                }
            }
            else if (arg1.data != null) 
            {
                loc1 = arg1.data as Array<any>;
                loc2 = new Map<any, any> /* flash.utils.Dictionary */();
                loc3 = false;
                var loc5=0;
                var loc6=loc1;
                for(loc4 of loc6) 
                {
                    if (!DelegateSettingRule.isGettingItem(loc4)) 
                    {
                        continue;
                    }
                    loc2[loc4.uid] = loc4.itemAmount;
                    loc3 = true;
                }
                if (loc3) 
                {
                    GameProxy.packProxy.moveBag(EPlayerItemPosType._EPlayerItemPosTypeDelegate, EPlayerItemPosType._EPlayerItemPosTypeBag, loc2);
                }
            }
            else 
            {
                GameProxy.packProxy.moveBag(EPlayerItemPosType._EPlayerItemPosTypeDelegate, EPlayerItemPosType._EPlayerItemPosTypeBag);
            }
            return;
        }

        /* internal  */onGetAllItemsSuccess(arg1: DataEvent): void
        {
            if (this._delegateHintIcon) 
            {
                this._delegateHintIcon.hide();
            }
            return;
        }

        /* internal  */onDestroyAllDelegateItem(arg1: DataEvent): void
        {
            GameProxy.delegateTask.cleanDelegateBag();
            return;
        }

        private /* var */_delegateTaskModule: IDelegateTaskModule;

        private /* var */_delegateWarehouse: DelegateWarehouse;

        private /* var */_delegateHintIcon: DelegateTaskHintIcon;

        private /* var */_reqTimer: Object /* flash.utils.Timer */;

        private /* var */_delegateTaskList: DataProvider;

        private /* var */_delegateTaskList_defenceCopy: DataProvider;

        private /* var */_delegateTaskList_CrossDefence: DataProvider;

        private /* var */_info: CanDelegateItemData;

        private /* var */_delegateTaskList_AllWithHighestDefence: DataProvider;

        private /* var */_inited: Boolean=false;

        private /* var */_tempDelegateTaskCode: int;
    }
